package gui;

import gui.dialog.SetUpGameDialog;
import gui.dialog.ErrorDialog;
import gui.dialog.DrawnDialog;
import gui.dialog.WinnerDialog;
import game.GameManager;
import gui.dialog.SetUpNetworkGameDialog;
/*
 * This class is the controller class between the Logic of the game 
 * and the graphics.
 */

public class GUIController {

    private GameManager gameManager;
    private GameFrame gameFrame;

    public GUIController(GameManager gameManager) {
        this.gameManager = gameManager;
        createGameFrame();
    }

    // ------ Create methods ------
    private void createGameFrame() {
        gameFrame = new GameFrame(this);
    }

    // ------ Get methods ------
    public GameManager getGameManager() {
        return gameManager;
    }

    public String getPlayer1Name() {
        return gameManager.getPlayer1Name();
    }

    public String getPlayer2Name() {
        return gameManager.getPlayer2Name();
    }

    public String getCurrentPlayer() {
        return gameManager.getPlayerName(
                gameManager.getCurrentPlayer());
    }

    // ------ Show Dialog methods ------
    protected void showSetUpGameDialog() {
        new SetUpGameDialog(this);
    }
    protected void showSetUpNetworkGameDialog(){
        new SetUpNetworkGameDialog(this);
    }

    public void showWinnerDialog(String playername) {
        new WinnerDialog(playername);
    }

    public void showDrawnDialog() {
        new DrawnDialog();
    }

    public void showErrorDialog(String message) {
        new ErrorDialog(message);
    }

    // ------ Update methods ------
    public void updateGameBoard() {
        gameFrame.repaintGameBoard();
    }

    public void updateCurrentPlayer() {
        gameFrame.updateCurrentPlayer();
    }
    /*
     * This method will start the four in a row game.
     */

    public void startGame() {
        gameManager.playGame();
    }

    /*
     * This method will clear the game grid and update the game board.
     */
    public void resetGameBoard() {
        gameManager.getGameGrid().clearGrid();
        updateCurrentPlayer();
        updateGameBoard();
    }
}
